	  <?php form_head("admin/allocation_edit/".$row["allocation_id"]."/".$type_id,"");
       //$user = $this->user->get();
	  ?>
          <?php //text_field("name","ชื่อผู้ขอเบิกจ่าย",array("name" =>$user["firstname"]." ".$user["lastname"]),"disable"); ?>
         <?php 

		 $rows =  $this->db->query("select concat(firstname,'  ',lastname) as name,user_id from  users")->result_array();

		 select_field("user_id","ชื่อผู้เบิก",$rows,"name",$row,"โปรดเลือก",null,"",2); 

		//select_field($name,$label,$rows,$label_value,$row,$cleaner = 0,$first_label="โปรดเลือก",$class ="",$type=1)

		 ?>
            <?php area_field("detail","รายละเอียดขอเบิกจ่าย",$row,1); ?>
            
            <?php 

		 $rows =  $this->db->query("select place_id,  place_name from  place")->result_array();

		 select_field("place_id","ห้องปฎิบัติการ/สถานที่",$rows,"place_name",$row,"โปรดเลือก",0,null,"",2); 

		//select_field($name,$label,$rows,$label_value,$row,$cleaner = 0,$first_label="โปรดเลือก",$class ="",$type=1)

		 ?>
         <?php 
		 $rows =  $this->db->get("meterial_base_categories")->result_array();
 ?>
 

   
  </form>
          
   <table class="list list-form" style="width:700px;">
   <thead>
   
          
            <th style="width: 150px;">หมวดวัสดุครุภัณพ์</th>
            
             <th style="width: 40px;">จำนวน</th>
              <th style="width: 200px;">รายละเอียด/หมาเหตุ</th>
             
            <th></th>
           
         
   </thead>
          <tbody id="items">
               <?php 
               $this->db->where("allocation_id",$row["allocation_id"]);
               $items = $this->db->get("allocation_item_views")->result_array(); 
               
               foreach($items as $item){
               
               ?>  
              <tr>
            <td><?php echo $item["category_name"]; ?></td>
            <td><?php echo $item["amount"]; ?></td>
             <td><?php echo $item["remark"]; ?></td>
            <td></td>
            <td> <a class="item_del" href="javascript:void(0);" data="<?php echo $item["allocation_item_id"]; ?>"> ลบ</a></td>
              </tr>
        <?php } ?>
         <tr>
              <td><?php $this->p->category_options(1,$type_id); ?> </td>
           <td><input id="amount" style="width: 40px;" name="amount" class="amount" value="<?php echo set_value("amount","1"); ?>" type="text" /></td>
           <td><input id="remark" style="width: 250px;" name="remark" class="remark" value="<?php echo set_value("remark"); ?>" type="text" /></td>
           	
            <td><input class="submit" type="button" onclick="add_item();" value="เพิ่มรายการ" /></td>
              </tr>
                  </tbody></table>
                 
 <div onclick="javascript:document.forms['myform'].submit();" class="btimg">บันทึก</div>                 
 <script type="text/javascript">
/*
 $(document).ready(function() {


	 $.ajax({
		  type: "POST",
		  url: "<?php echo site_url("service/teacher_request_item"); ?>/view",
		  data: "",
		  success: function(data) {
			  $('#items').html(data);
	 	}
		});
	 
	});
*/
 
function add_item()
{
 var category_id = $("#category_id").val();
 var amount = $("#amount").val();
 var remark = $("#remark").val();
 var allocation_id = '<?php echo $row["allocation_id"]; ?>';
 $.ajax({
	  type: "POST",
	  url: "<?php echo site_url("service/allocation_item_add"); ?>",
	  data: "category_id="+category_id+"&amount="+amount+"&remark="+remark+"&allocation_id="+allocation_id,
	  success: function(data) {
		  window.location.reload();
 	}
	});

}
$("a.item_del").click(function(){ 

	var id = $(this).attr("data");
	
	 $.ajax({
		  type: "POST",
		  url: "<?php echo site_url("service/allocation_item_delete"); ?>/"+id,
		  
		  success: function(data) {
			window.location.reload();
	 	}
		});
	
});

function remove_item(id)
{
	
	 $.ajax({
		  type: "POST",
		  url: "<?php echo site_url("service/teacher_request_item"); ?>/delete",
		  data: "category_id="+id,
		  success: function(data) {
			  $('#items').html(data);
	 	}
		});
}
 </script>

